<template>
  <div>
    <div>
      <FormPanel ref="formPanel" :list="formList" :cols="1" :labelWidth="150" :isSubmitBtn="false" @formChange="formChangeHandle" />
    </div>
    <p>根据选择的基准价类型、输入的加价率和选择的调整价类型进行批量修改</p>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <el-button @click="closeDialog">取 消</el-button>
      <el-button type="primary" @click="saveDialog">保 存</el-button>
    </div>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { changePrice } from '@/api/part/inventoryManager/partPriceAdjust';

export default {
  name: 'BrandModal',
  mixins: [dictionary],
  props: ['type'],
  data() {
    this.conf = { add: '保 存', edit: '修 改' };
    this.saveData = null;
    return {
      formList: this.createFormList()
    };
  },
  computed: {
    btnText() {
      return this.conf[this.type];
    }
  },
  created() {},
  methods: {
    createFormList() {
      return [
        {
          type: 'SELECT',
          label: '基准价类型',
          fieldName: 'baseCostType',
          placeholder: '请选择',
          itemList: [
            { value: 12361001, text: '成本价' },
            { value: 12361002, text: '销售价' },
            { value: 12361003, text: '索赔价' },
            { value: 12361004, text: '网点价' },
            { value: 12361005, text: '最新进货价' },
            { value: 12361007, text: '终端建议零售价格' },
            { value: 12361008, text: '建议销售价' },
            { value: 12361009, text: '销售限价' }
          ],
          rules: [{ required: false, message: '请选择基准价类型', trigger: 'change' }]
        },
        {
          type: 'INPUT',
          label: '加价率',
          fieldName: 'markupPercentage',
          placeholder: '请输入...',
          rules: [{ required: true, message: '请输入加价率', trigger: 'blur' }]
        },
        {
          type: 'SELECT',
          label: '调整价类型',
          fieldName: 'isCostType',
          placeholder: '请选择',
          itemList: [
            { value: 12361002, text: '销售价' },
            { value: 12361004, text: '网点价' },
            { value: 12361007, text: '终端建议零售价格' }
          ],
          rules: [{ required: false, message: '请选择调整价类型', trigger: 'change' }]
        },
        {
          type: 'SELECT',
          label: '调整价格四舍五入',
          fieldName: 'price',
          placeholder: '请选择',
          itemList: [
            { value: 12921001, text: '元' },
            { value: 12921002, text: '角' },
            { value: 12921003, text: '分' }
          ],
          rules: [{ required: false, message: '请选择调整价格四舍五入', trigger: 'change' }]
        },
        {
          type: 'SELECT',
          label: '最新进货价格为零不调整',
          fieldName: 'saCost',
          placeholder: '请选择',
          itemList: this.createDictList('1004'),
          rules: [{ required: false, message: '请选择最新进货价格为零不调整', trigger: 'change' }]
        },
        {
          type: 'SELECT',
          label: '基准价格为零不调整',
          fieldName: 'sadCost',
          placeholder: '请选择',
          itemList: this.createDictList('1004'),
          rules: [{ required: false, message: '请选择基准价格为零不调整', trigger: 'change' }]
        },
        {
          type: 'SELECT',
          label: 'OEM索赔价不调整',
          fieldName: 'saddCost',
          placeholder: '请选择',
          itemList: this.createDictList('1004'),
          rules: [{ required: false, message: '请选择OEM索赔价不调整', trigger: 'change' }]
        }
      ];
    },
    formChangeHandle(val) {
      console.log(val);
      this.saveData = val;
    },
    async saveDialog() {
      // debugger;
      this.$refs.formPanel.SUBMIT_FORM();
      let partNo = '';
      let storage = '';
      let partBatch = '';
      for (let i = 0; i < this.type.length; i++) {
        partNo += this.type[i].partNo + ',';
        storage += this.type[i].storageCode + ',';
        partBatch += this.type[i].partBatchNo + ',';
      }
      let obj = {
        partNo: partNo,
        storage: storage,
        partBatch: partBatch,
        BASE_COST_TYPE: this.formList[0].initialValue,
        markup_percentage: this.formList[1].initialValue,
        IS_COST_TYPE: this.formList[2].initialValue,
        Price: this.formList[3].initialValue,
        saCost: this.formList[4].initialValue,
        sadCost: this.formList[5].initialValue,
        saddCost: this.formList[6].initialValue
      };
      let res = await changePrice(obj);
      if (res.resultCode == '200') {
        this.test();
      }
    },
    closeDialog() {
      this.$emit('close');
    },
    test() {
      this.$notify({
        title: '成功',
        message: '成功',
        type: 'success'
      });
      this.closeDialog('refresh');
    }
  }
};
</script>

<style lang="less" scoped></style>
